package exercises.Charpter9;

abstract class Rodent {
	static long counter;
	static{
		counter = 0;
	}
	public Rodent() {
		System.out.println("Rodent initialized.");
		counter++;
	}
	void bite(){
		System.out.println("Rodent bite");
	}
	void dispose() throws Throwable{
		counter--;
		if (counter == 0){
			super.finalize();
		}
	}
}

class Mouse extends Rodent{
	public Mouse() {
		System.out.println("Mouse initialized.");
	}
	@Override
	void bite(){
		System.out.println("Mouse bite");
	}
}

class Gerbil extends Rodent{
	public Gerbil() {
		System.out.println("Gerbil initialized.");
	}
	@Override
	void bite(){
		System.out.println("Gerbil bite");
	}
}

class Hamster extends Rodent{
	public Hamster() {
		System.out.println("Hamster initialized.");
	}
	@Override
	void bite(){
		System.out.println("Hamster bite");
	}
}

public class One {
	public static void main(String[] args){
		Rodent[] rodents = {
				new Mouse(),
				new Gerbil(),
				new Hamster(),
		};
		for(Rodent t:rodents){
			t.bite();
		}
	}
}
